package com.srv.model.json;

import java.util.ArrayList;
import java.util.Date;

import org.codehaus.jackson.map.ObjectMapper;

import com.srv.model.Travel;;

public class Travel_Json4Owner implements java.io.Serializable,JSON_UTF8 {
	public Travel_Json4Owner(Travel theTravel){
		this.id=theTravel.travelID;
		this.createTime=theTravel.createTime;
		this.updateTime=theTravel.updateTime;
		this.favorNum=theTravel.favorNum;
		this.downloadNum=theTravel.downloadNum;
		this.rePubNum=theTravel.rePubNum;
		this.title=theTravel.title;
		this.isClose=theTravel.isClose();
		this.finishTime=theTravel.finishTime;		
	}
	/**
	 * ID
	 */
    public String id = null;
    
    /**
     * 标题
     */
	public String title = null;
	
	/**
     * 结束时间
     */
    public Date finishTime = null;
    
    /**
     * 是否关闭
     */
    public boolean isClose = false;
    
    /**
	 * 收藏次数
	 */
    public long favorNum = 0;
    /**
	 * 下载次数
	 */
    public long downloadNum = 0;
    /**
	 * 转发次数
	 */
    public long rePubNum = 0;
    
    /**
     * 创建时间
     */
    public Date createTime = null;
    /**
     * 更新时间
     */
    public Date updateTime = null;
    
    /**
	 * 转换成UTF-8的Json
	 * @return
	 */
    public String toJson_utf8() throws Exception{
    	ObjectMapper mapper = new ObjectMapper();
        mapper.registerSubtypes(Travel_Json4Owner.class);
//        System.out.println(mapper.writeValueAsString(this));
    	return mapper.writeValueAsString(this);    	                
    }
    /**
     * 转换
     * @param travelArrayList
     * @return
     */
    public static ArrayList<Travel_Json4Owner> convert(ArrayList<Travel> travelArrayList){
    	ArrayList al=new ArrayList();
    	for(int i=0; i<travelArrayList.size();i++){
    		al.add(new Travel_Json4Owner(travelArrayList.get(i)));
    	}
    	return al;
    }

}
